package com.travel.dao.impl;

import java.util.List;
import java.util.Objects;

import com.travel.core.AbstractDao;
import com.travel.dao.ILocalSpecialGoodsDao;
import com.travel.entities.GoodsEntity;

/**
 * @author SAGITTAR
 */
public class LocalSpecialGoodsDaoImpl extends AbstractDao implements ILocalSpecialGoodsDao {

    @Override
    public List<GoodsEntity> getTopGoods(String loc, String orderBy, Direction direction) {
        String sql = "SELECT shop_name shopName, shop_url shopUrl, item_name itemName, item_url itemUrl, item_sale itemSale, item_rate_num itemRateNum ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append("FROM good_item ");
        sqlBuilder.append("WHERE city = ? ");
        sqlBuilder.append("AND item_sale > 1 ");
        sqlBuilder.append("ORDER BY %s %s ");
        sqlBuilder.append("LIMIT 0, 14");
        if (Objects.isNull(direction)) {
            direction = Direction.DESC;
        }
        String preparedSql = String.format(sqlBuilder.toString(), orderBy, direction);
        return selectListByClassTypeAndSql(GoodsEntity.class, preparedSql, loc);
    }
}
